package ils.web.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import ils.domain.catalog.model.Category;
import ils.services.CatalogService;
import ils.util.SpringUtil;
import org.apache.struts2.interceptor.SessionAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: rejeevd
 * Date: 29/09/12
 * Time: 20:53
 * To change this template use File | Settings | File Templates.
 */
public class CategoriesAction extends ActionSupport implements SessionAware, Preparable
{
    private static final Logger logger = LoggerFactory.getLogger(CategoriesAction.class);
    private Map<String, Object> session;
    private CatalogService catalogService;
    private List<Category> categories;

    @Override
    public void setSession(Map<String, Object> stringObjectMap) {
        this.session = stringObjectMap;
    }

    @Override
    public String execute()
    {
        categories = catalogService.getSubCategories(null);
        return SUCCESS;
    }

    @Override
    public void prepare()
    {
        catalogService = (CatalogService) SpringUtil.getApplicationContext().getBean("catalogService");
    }

    public List<Category> getCategories() {
        return categories;
    }

    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }
}
